package com.wust.supermarket.service.impl;

import com.wust.supermarket.dao.MerchDao;
import com.wust.supermarket.domain.Merch;
import com.wust.supermarket.service.MerchService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class MerchServiceImpl implements MerchService {

    @Resource
    private MerchDao merchDao;

    @Override
    public List<Merch> listAllMerches() {
        return merchDao.listAllMerches();
    }

    @Override
    public List<Merch> listAllOffMerchs() {
        return merchDao.listAllOffMerchs();
    }

    @Override
    public Merch getMerchById(int merchId) {
        return merchDao.getMerchById(merchId);
    }

    @Override
    public int insertMerch(Merch merch) {
        return merchDao.insertMerch(merch);
    }

    @Override
    public boolean updateMerch(Merch merch) {
        return merchDao.updateMerch(merch)>0;
    }

    @Override
    public int deleteMerch(int merchId) {
        return merchDao.deleteMerch(merchId);
    }

    @Override
    public int getMerchNumber() {
       List<Merch>merches= merchDao.listAllMerches();
       int num=0;
        for (Merch m:merches
             ) {
            num=num+m.getMerchNumber();
        }
        return  num;
    }
}
